<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        :root {
            --bg: #eee;
            --text-color: black;
        }

        html[data-theme="dark"] {
            --bg: gray;
            --text-color: white;
        }

        .box {
            background: var(--bg);
            color: var(--text-color);
            height: 50vh;
        }
    </style>
    <script>
        function change() {
            const dom = document.querySelector('.box')
            console.log(document.documentElement)
            document.documentElement.dataset['theme'] = document.documentElement.dataset['theme'] == 'dark' ? '' : 'dark'
        }
    </script>
</head>

<body>
    <div onclick="change()" id="aaa">切换主题</div>
    <div class="box">111</div>
</body>

</html>